<?php
namespace Admin\Controller;
use JPush\Client as JPush;
class PushController extends AdminController {

    private  $app_key = 'd6bede8db785173f14856f13';

    private $master_secret = 'f607c96d28d2449120913361';


    public function pushOrder($title,$Alias){
        $client = new JPush($this->app_key, $this->master_secret);
        try {
            $pusher = $client->push();
            $pusher->setPlatform('all');
            //$pusher->addAlias($Alias);
            $pusher->setNotificationAlert($title);
            $pusher->androidNotification($title, array(
                'sound' => 'newOrder.m4a',
                'title' => $title,
                'extras' => array(
                    'jiguang'
                ),
            ));
            $pusher->iosNotification($title, array(
                'sound' => 'newOrder.m4a',
                'badge' => '+1',
                'content-available' => true,
                'category' => 'jiguang',
                'extras' => array(
                    'jiguang'
                ),
            ));
            $pusher->options(array(
                'apns_production' => false));

        } catch (\JPush\Exceptions\APIConnectionException $e) {
            response(-2,array('msg'=>$e),'对方没有登录');
        } catch (\JPush\Exceptions\APIRequestException $e) {
            response(-2,array('msg'=>$e),'对方没有登录');
        }

        $result = $pusher->send();
        $report = $client->report();

        $rep = $report->getReceived($result['body']['msg_id']);
//            推送成功 更改状态
        if ($rep['http_code']==200)
        {
            return true;
        }else{
            return false;
        }
        //return true;
    }


    /**
     *查询推送消息
     *token
     */
    public function queryPushLog(){

        !api_login() && response(-94);
        !passed_login() && response(-95);
        !only_login() && response(-96);


        $log  = M('push_log');

        $map['uid'] = API_UID;

        $data = $log->field('meter_no,content,create_time')->where($map)->order('create_time desc')->select();

        empty($data)?response(-500):response(200,$data);

    }





}
?>